<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <button>get</button>
    <button>post</button>
</body>
<script>
    const btns = document.querySelectorAll("button");
    btns[0].onclick = function(){
        const xhr = new XMLHttpRequest();
        xhr.responseType = "json";
        xhr.open("get","http://zhangpeiyue.com/scoreList?sex=男");
        xhr.send();
        xhr.onload = function(){
            console.log(xhr.response);
        }
    }
    btns[1].onclick = function(){
        // 1- 请求体写在哪
        // 2- 请求体的格式如何设置
        // const xhr = new XMLHttpRequest();
        // xhr.responseType = "json";
        // xhr.open("post","http://zhangpeiyue.com/scoreList");
        // xhr.setRequestHeader("Content-Type","application/json");
        // xhr.send(JSON.stringify({
        //     userName:"刘德华",
        //     age:12
        // }));
        // xhr.onload = function(){
        //     console.log(xhr.response);
        // }


        const xhr = new XMLHttpRequest();
        xhr.responseType = "json";
        xhr.open("post","http://zhangpeiyue.com/scoreList");
        xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        xhr.send("userName=蔡徐坤&age=80");
        xhr.onload = function(){
            console.log(xhr.response);
        }
    }
</script>
</html>